<?php 
// <h1>验证码</h1>
// 创建画布
$width=300;
$height=100;
$img=imagecreatetruecolor($width, $height);
  
//设置绘图颜色
$color=imagecolorallocate($img,90 ,196,18);
//填充颜色
imagefill($img,0 ,0 , $color);
//随机的数字
$a=array_merge( range(0,9),range("a","z"),range("A","Z"));
$b=array_flip($a);
//print_r (array_rand($b,4));
$c=array_rand($b,4);
//var_dump (implode("",$c));
$color1=imagecolorallocate($img, rand(0,125), rand(0,125), rand(0,125));

$d=implode("",$c);
 $f= imagettftext($img, 50, mt_rand(-15,15), $height, $width/5, $color1, "/public/fonts/mnjhc.ttf", $d);
//添加干扰
for ($i=1; $i<=50 ; $i++) {
    $color2=imagecolorallocate($img, rand(0,125), rand(0,125), rand(0,125));
    imageline($img, rand(0,$width), rand(0,$height), rand(0,$width), rand(0,$height), $color2);
}
for ($i=1; $i<=1000 ; $i++){
    $color3=imagecolorallocate($img, rand(0,125), rand(0,125), rand(0,125));
    imagesetpixel($img, rand(0,$width), rand(0,$height), $color3);
}

//输出图像
header("Content-type:image/png");
imagepng($img);  
?>